//
//  DCLoanExtensionController.m
//  Demo
//
//  Created by zhaolin on 2023/2/6.
//

#import "DCLoanExtensionController.h"
#import "DCLoanDetialCell.h"

@interface DCLoanExtensionController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UILabel *moneyLabel;

@property (nonatomic, strong) UILabel *daysNumLabel;

@property (nonatomic, strong) UIButton *statusBtn;

@property (nonatomic, strong) NSMutableArray *dataSource;
@end

@implementation DCLoanExtensionController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitleName:@"Extension"];

    // Do any additional setup after loading the view.
}
- (void)configureUI {
    [super configureUI];
    self.navgitBar.backgroundColor = [UIColor colorWithString:@"#F0FFCE"];
    
    UIButton *privacyAgreementBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [privacyAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [privacyAgreementBtn addTarget:self action:@selector(privacyAgreementBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [privacyAgreementBtn setTitleColor:[UIColor colorWithString:@"#000000"] forState:UIControlStateNormal];
    privacyAgreementBtn.titleLabel.font = DCFont_PF_Regular(11);
    [self.view addSubview:privacyAgreementBtn];
    [privacyAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(-KSafeAreaInset.bottom-20);
        make.height.mas_equalTo(16);
    }];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.tableView registerClass:DCLoanDetialCell.class forCellReuseIdentifier:NSStringFromClass(DCLoanDetialCell.class)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = self.view.backgroundColor ;
    self.tableView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.navgitBar.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(privacyAgreementBtn.mas_top).mas_offset(-10);
    }];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 286 + 20 + KSafeAreaInset.top)];;
    self.tableView.tableHeaderView = headerView;
    
    UIView *colorView = [UIView new];
    colorView.backgroundColor = [UIColor colorWithString:@"#F0FFCE"];
    [headerView addSubview:colorView];
    [colorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(154+KSafeAreaInset.top);
    }];
        
    UIView *cornerRadiusView = [UIView new];
    cornerRadiusView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    cornerRadiusView.layer.cornerRadius = 30;
    cornerRadiusView.layer.masksToBounds = YES;
    [headerView addSubview:cornerRadiusView];
    [cornerRadiusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(colorView.mas_bottom);
    }];
    
    UIImageView *colorImage = [UIImageView new];
    colorImage.layer.cornerRadius = 8;
    colorImage.layer.masksToBounds = YES;
    colorImage.backgroundColor = [UIColor colorWithString:@"#1C221B"];
    [colorView addSubview:colorImage];
    [colorImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(36);
        make.bottom.mas_equalTo(cornerRadiusView.mas_top).mas_offset(-33);
        make.width.height.mas_equalTo(36);
    }];
    
    UILabel *numberLabel = [UILabel new];
    numberLabel.text = @"009900";
    numberLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    numberLabel.font = DCFont_PF_Medium(14);
    [colorView addSubview:numberLabel];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(colorImage.mas_right).mas_offset(10);
        make.centerY.mas_equalTo(colorImage.mas_centerY);
    }];
    
    UIButton *statusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _statusBtn = statusBtn;
    statusBtn.titleLabel.font = DCFont_PF_Medium(14);
    [statusBtn setTitle:@"Extension" forState:UIControlStateNormal];
    [statusBtn setTitleColor:[UIColor colorWithString:@"#658900"] forState:UIControlStateNormal];
    [colorView addSubview:statusBtn];
    [statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-36);
        make.centerY.mas_equalTo(colorImage.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    
    UIView *whiteView = [UIView new];
//    whiteView.backgroundColor = [UIColor cyanColor];
    whiteView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    [headerView addSubview:whiteView];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(cornerRadiusView.mas_centerY);
    }];
    
    UILabel *moneyDes = [UILabel new];
    moneyDes.font = DCFont_PF_Light(12);
    moneyDes.text = @"Extension fee";
    moneyDes.textColor = [UIColor colorWithString:@"#1C221B"];
    [whiteView addSubview:moneyDes];
    [moneyDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(13);
        make.left.mas_equalTo(46);
    }];
    
    UILabel *moneyLabel = [UILabel new];
    _moneyLabel = moneyLabel;
    moneyLabel.font = DCFont_PF_Medium(26);
    moneyLabel.text = @"₦3,000";
    moneyLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    [whiteView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(moneyDes);
        make.top.mas_equalTo(moneyDes.mas_bottom).mas_offset(10);
    }];
    
    UILabel *dateDes = [UILabel new];
    dateDes.font = DCFont_PF_Light(12);
    dateDes.text = @"New due date";
    dateDes.textColor = [UIColor colorWithString:@"#1C221B"];
    [whiteView addSubview:dateDes];
    [dateDes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(13);
        make.right.mas_equalTo(-46);
    }];
    
    
    
    UILabel *dayLabel = [UILabel new];
    dayLabel.font = DCFont_PF_Regular(16);
    dayLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    dayLabel.text = @"days";
    [whiteView addSubview:dayLabel];
    [dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(dateDes);
        make.bottom.mas_equalTo(moneyLabel.mas_bottom).mas_offset(-2);
    }];
    
    UILabel *dateLabel = [UILabel new];
    _daysNumLabel = dateLabel;
    dateLabel.font = DCFont_PF_Medium(26);
    dateLabel.text = @"120";
    dateLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    [whiteView addSubview:dateLabel];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(dayLabel.mas_left);
        make.bottom.mas_equalTo(dayLabel.mas_bottom).mas_offset(2);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = [UIColor colorWithString:@"#1C221B"];
    [whiteView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(moneyLabel.mas_bottom).mas_offset(26);
        make.left.mas_equalTo(31);
        make.right.mas_equalTo(-31);
        make.height.mas_equalTo(1);
    }];
    
    UIImageView *logoImage = [UIImageView new];
    logoImage.image = [UIImage imageNamed:@"wodedingdan"];
//    logoImage.backgroundColor = [UIColor redColor];
    [whiteView addSubview:logoImage];
    [logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(42);
        make.top.mas_equalTo(lineView.mas_bottom).mas_offset(35);
        make.width.height.mas_equalTo(25);
    }];
    
    UILabel *detialLabel = [UILabel new];
    detialLabel.text = @"Extension details";
    detialLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    detialLabel.font = DCFont_PF_Medium(15);
    [whiteView addSubview:detialLabel];
    [detialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(logoImage.mas_centerY);
        make.left.mas_equalTo(logoImage.mas_right).mas_offset(10);
    }];

    self.tableView.tableFooterView = [self tableViewFooter];
}

- (UIView *)tableViewFooter {
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];
    footerView.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmBtn.layer.cornerRadius = 8;
    confirmBtn.layer.masksToBounds = YES;
    confirmBtn.backgroundColor = [UIColor colorWithString:@"#1C221B"];
    confirmBtn.titleLabel.font = DCFont_PF_Semibold(15);
    [confirmBtn setTitleColor:[UIColor colorWithString:@"#FFFFFF"] forState:UIControlStateNormal];
    [confirmBtn setTitle:@"Confirm and apply" forState:UIControlStateNormal];
    [confirmBtn addTarget:self action:@selector(confirmBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(38);
        make.centerY.mas_equalTo(footerView.mas_centerY);
        make.right.mas_equalTo(-38);
        make.height.mas_equalTo(50);
    }];
    
    return footerView;
}
#pragma mark - tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DCLoanDetialCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(DCLoanDetialCell.class)];
    NSDictionary *dic = [self.dataSource objectAtIndex:indexPath.row];
    [cell configureData:dic];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 35;
}

- (void)privacyAgreementBtnAction:(UIButton *)sender {
    DCWebModel *webInfo = [DCWebModel creatPrivacyAgreement];
    DCWebViewController *webVC = [[DCWebViewController alloc] initWithModel:webInfo];
    [self.navigationController pushViewController:webVC animated:YES];
}

- (void)confirmBtnAction:(UIButton *)sender {
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
